package com.travel.server.manager.impl.command.adversiting;

import com.travel.common.CommonConstant;
import com.travel.server.manager.dto.request.advertising.DeleteAdvertisingSourceRequest;
import com.travel.server.manager.dto.response.EmptyResponse;
import com.travel.server.manager.impl.command.AbstractCommand;
import com.travel.server.manager.impl.dal.SourceDal;
import com.travel.server.manager.model.AdvertisingSourceInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: LiZhenhui
 * @Date: 2018/12/20 15:43
 * @Desc:
 */
@Component
public class DeleteAdvertisingSourceCommand extends AbstractCommand<DeleteAdvertisingSourceRequest, EmptyResponse> {

    @Autowired
    private SourceDal sourceDal;

    @Override
    protected void checkInput(DeleteAdvertisingSourceRequest request) {
        if(request.getId() == null){
            throwInvalidParam();
        }
    }

    @Override
    public EmptyResponse handle(DeleteAdvertisingSourceRequest request) {
        checkInput(request);

        AdvertisingSourceInfo info = sourceDal.selectById(request.getId());
        info.setState(CommonConstant.NO);
        info.setUpdateTime(new Date());
        info.setUpdateBy(getUserInfo().getName());
        sourceDal.insertOrUpdate(info);
        return new EmptyResponse();
    }
}
